<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加学生选课信息</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.3.js"></script>
    <style type="text/css">
        #studentSubjectForm{
            text-align: center;
        }
    </style>
    <script>
        function toSubmit(){
            var stuId = $("#stuId option:selected").val();
            var subId = $("#subId option:selected").val();
            $.ajax({
                Type:"POST",
                url:"/scvs/studentSubject/check",
                data:{
                    stuId:stuId,
                    subId:subId
                },
                dataType:"json",
                success:function (data){
                    console.log(data);
                    if(data){
                        $("#studentSubjectForm").submit();
                    }else{
                        $("#msg").text("该选课信息已存在，请重新添加");
                    }
                }
            });
        }
    </script>
</head>
<body>
<%@include file="../common/headManager.jsp" %>
<form id="studentSubjectForm" action="/scvs/studentSubject/add" method="post">
    <label>学生</label>
    <select id="stuId" name="stuId">
        <c:forEach items="${students}" var="item">
            <option value="${item.id}">${item.realName}</option>
        </c:forEach>
    </select>
    <label>课程</label>
    <select id="subId" name="subId">
        <c:forEach items="${subjects}" var="item">
            <option value="${item.id}">${item.name}</option>
        </c:forEach>
    </select>
    <input type="button" onclick="toSubmit()" value="提交"/><br>
    <span id="msg"></span>
</form>
</body>
</html>
